//
//  RemarkInputCell.m
//  Guazi
//
//  Created by koolearn on 11-7-30.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>
#import "RemarkInputCell.h"


@implementation RemarkInputCell

@synthesize textView;
@synthesize footer;
@synthesize message;
@synthesize controller;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.textView = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
        textView.delegate = self;
        textView.font = [UIFont systemFontOfSize:14];
       [self.contentView addSubview:textView];
        
        self.footer = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
        footer.backgroundColor = [UIColor colorWithRed:0.75f green:0.75f blue:0.75f alpha:1.0f];
        [self.contentView addSubview:footer];
        
        self.message = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
        message.backgroundColor = footer.backgroundColor;
        message.textColor = [UIColor whiteColor];
        message.textAlignment = UITextAlignmentLeft;
        message.font = [UIFont systemFontOfSize:13];
        message.text = @"可输入字数 140";
        [self.contentView addSubview:message];
    }
    return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void) layoutSubviews
{
    [super layoutSubviews];

    textView.frame = CGRectMake(0, 0, 320, 165);
    textView.layer.masksToBounds=YES;
    //textView.layer.cornerRadius=5.0;
    textView.layer.borderWidth=2.0;
    textView.layer.borderColor=[[UIColor lightGrayColor] CGColor]; 

    footer.frame = CGRectMake(0, 165, 320, 30);
    message.frame = CGRectMake(10, 170, 280, 20);
}


- (void)dealloc
{
    [textView release];
    [footer release];
    [message release];
    [controller release];
    [super dealloc];
}


#pragma mark - TextViewDelegate

- (void)textViewDidChange:(UITextView *)tv
{
    NSInteger length = [tv.text length];
    NSInteger count = 140 - length;
    
    message.text = [NSString stringWithFormat:@"可输入字数 %d", count];
    controller.inputRemark = tv.text;
}

@end
